import { ApiProperty } from '@nestjs/swagger';
import { Transform, Type } from 'class-transformer';
import { IsBoolean, IsEnum, IsOptional, IsString, IsUUID, Min } from 'class-validator';
import { PagingReqDto } from '../../../../common/dtos/paging.req.dto';

export class GetUserListAdminReqDto extends PagingReqDto {
  @ApiProperty({ description: '排序字段', enum: ['createdAt'] })
  @IsEnum(['createdAt'], { message: '排序字段格式不正确' })
  readonly order_by: string;

  @ApiProperty({ description: '组织Uuid', required: false })
  @Type(() => Number)
  @Min(1, { message: '组织编号格式不正确' })
  @IsOptional()
  readonly organization_id: number;

  @ApiProperty({ description: '用户名称模糊查询', required: false })
  @IsString({ message: '用户名称模糊查询格式不正确' })
  @IsOptional()
  readonly name: string;

  @ApiProperty({ description: '邮箱', required: false })
  @IsString({ message: '邮箱模糊查询格式不正确' })
  @IsOptional()
  readonly email: string;

  @ApiProperty({ description: '手机号码', required: false })
  @IsString({ message: '手机号码模糊查询格式不正确' })
  @IsOptional()
  readonly mobile: string;

  @ApiProperty({ description: '角色uuid', required: false })
  @IsUUID('4', { message: '角色uuid格式不正确' })
  @IsOptional()
  readonly role_uuid: string;

  @ApiProperty({ description: '是否包含角色', default: true, required: false })
  @Transform(value => (value && typeof value === 'string' ? value === 'true' : value))
  @IsBoolean({ message: '是否包含角色格式不正确' })
  @IsOptional()
  readonly include_role: boolean;
}
